/*
@title: solar_system
@description: This game is a simulation that visually represents a simplified model of the solar system with orbiting planets. While it includes planets like Mercury, Venus, Earth, and others, the scale is noted to be inaccurate. It provides an interactive way to observe the relative positions of these celestial bodies around the sun.
@author: CD
@tags: ['simulation']
@addedOn: 2022-11-23
*/

/*
note: scale is inaccurate.
*/

const sun = "s";
const mercury = "m";
const venus = "v";
const earth = "e";
const mars = "a";
const jupiter = "j";
const saturn = "t";
const uranus = "u";
const neptune = "n";
const stars = "r";
const music = tune`
229.00763358778627: f4~229.00763358778627 + e4^229.00763358778627 + g4-229.00763358778627 + d4/229.00763358778627,
229.00763358778627: g4~229.00763358778627 + f4^229.00763358778627 + a4-229.00763358778627 + e4/229.00763358778627,
229.00763358778627: f4~229.00763358778627 + e4^229.00763358778627 + g4-229.00763358778627 + d4/229.00763358778627,
229.00763358778627: g4~229.00763358778627 + f4^229.00763358778627 + a4-229.00763358778627 + e4/229.00763358778627,
229.00763358778627: a4~229.00763358778627 + g4^229.00763358778627 + b4-229.00763358778627 + f4/229.00763358778627,
229.00763358778627: b4~229.00763358778627 + a4^229.00763358778627 + c5-229.00763358778627 + g4/229.00763358778627,
229.00763358778627: a4~229.00763358778627 + g4^229.00763358778627 + b4-229.00763358778627 + f4/229.00763358778627,
229.00763358778627: b4~229.00763358778627 + a4^229.00763358778627 + c5-229.00763358778627 + g4/229.00763358778627,
229.00763358778627: c5~229.00763358778627 + b4^229.00763358778627 + d5-229.00763358778627 + a4/229.00763358778627,
229.00763358778627: d5~229.00763358778627 + c5^229.00763358778627 + e5-229.00763358778627 + b4/229.00763358778627,
229.00763358778627: c5~229.00763358778627 + b4^229.00763358778627 + d5-229.00763358778627 + a4/229.00763358778627,
229.00763358778627: d5~229.00763358778627 + c5^229.00763358778627 + e5-229.00763358778627 + b4/229.00763358778627,
229.00763358778627: e5~229.00763358778627 + d5^229.00763358778627 + f5-229.00763358778627 + c5/229.00763358778627,
229.00763358778627: f5~229.00763358778627 + e5^229.00763358778627 + g5-229.00763358778627 + d5/229.00763358778627,
229.00763358778627: a5~229.00763358778627 + g5^229.00763358778627 + b5-229.00763358778627 + f5/229.00763358778627,
229.00763358778627,
229.00763358778627: f5~229.00763358778627 + e5^229.00763358778627 + g5-229.00763358778627 + d5/229.00763358778627,
229.00763358778627: e5~229.00763358778627 + d5^229.00763358778627 + f5-229.00763358778627 + c5/229.00763358778627,
229.00763358778627: f5~229.00763358778627 + e5^229.00763358778627 + g5-229.00763358778627 + d5/229.00763358778627,
229.00763358778627: e5~229.00763358778627 + d5^229.00763358778627 + f5-229.00763358778627 + c5/229.00763358778627,
229.00763358778627: f5~229.00763358778627 + e5^229.00763358778627 + g5-229.00763358778627 + d5/229.00763358778627,
229.00763358778627: e5~229.00763358778627 + d5^229.00763358778627 + f5-229.00763358778627 + c5/229.00763358778627,
229.00763358778627: d5~229.00763358778627 + c5^229.00763358778627 + e5-229.00763358778627 + b4/229.00763358778627,
229.00763358778627: e5~229.00763358778627 + d5^229.00763358778627 + f5-229.00763358778627 + c5/229.00763358778627,
229.00763358778627: d5~229.00763358778627 + c5^229.00763358778627 + e5-229.00763358778627 + b4/229.00763358778627,
229.00763358778627: e5~229.00763358778627 + d5^229.00763358778627 + f5-229.00763358778627 + c5/229.00763358778627,
229.00763358778627: c5~229.00763358778627 + b4^229.00763358778627 + d5-229.00763358778627 + a4/229.00763358778627,
229.00763358778627: b4~229.00763358778627 + a4^229.00763358778627 + c5-229.00763358778627 + g4/229.00763358778627,
229.00763358778627: c5~229.00763358778627 + b4^229.00763358778627 + d5-229.00763358778627 + a4/229.00763358778627,
229.00763358778627: b4~229.00763358778627 + a4^229.00763358778627 + c5-229.00763358778627 + g4/229.00763358778627,
229.00763358778627,
229.00763358778627: a4~229.00763358778627 + g4^229.00763358778627 + b4-229.00763358778627 + f4/229.00763358778627`;
const background = "0"

var rot = 0;

setLegend(
  [ sun,bitmap`
6666666666666666
6666266662666666
6666666666666666
6669666666669666
6666666666666666
6666629662666666
6666926332666626
6266623292966666
6666269323626666
6666262292266626
6666669666666666
6266666666666666
6666666626626266
6666966666666666
6666666666666666
6666666662666666`],
  [ mercury,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000L10000000
0000000LL0000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ venus,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
000000L120000000
000000L110000000
000000LLL0000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ earth,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000004777000000
0000007774000000
0000007744000000
0000004777000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ mars,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000990000000
0000000390000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ jupiter,bitmap`
0000000000000000
0000000000000000
0000000000000000
000C999999990000
000C999669660000
000F666666690000
000C999999990000
000F666C36660000
000C999CC9990000
000C999666660000
000F666699990000
000CCCCCCCCC0000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ saturn,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
000000F666000000
0009CCF666CC9000
0009999999999000
000000FFFF000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ uranus,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000001220000000
0000001220000000
0000001110000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ neptune,bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000577000000
0000000577000000
0000000555000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ stars,bitmap`
0000000000000000
0002000002000000
0000000000000002
0000000000000000
0000000000000000
0000000000000200
0200002000000000
0000000000000000
0000000000020000
0000000200000000
0000000000000000
2000000000000000
0000000000000020
0000200000020000
0200000000000000
0000000000000002`],
  [ background, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`]
);
setSolids([]);

let level = 0;
const levels = [
  map`
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000smveajtun
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000`,
];

setMap(levels[level]);
setBackground(background)
movePlanets();

function movePlanets(rotate){
  const p1 = getFirst(sun);
  const p2 = getFirst(mercury);
  const p3 = getFirst(venus);
  const p4 = getFirst(earth);
  const p5 = getFirst(mars);
  const p6 = getFirst(jupiter);
  const p7 = getFirst(saturn);
  const p8 = getFirst(uranus);
  const p9 = getFirst(neptune);
  p2.x = 8+Math.round(Math.sin(rotate*5)*1)
  p2.y = 8+Math.round(Math.cos(rotate*5)*1)
  p3.x = 8+Math.round(Math.sin(rotate*4)*2)
  p3.y = 8+Math.round(Math.cos(rotate*4)*2)
  p4.x = 8+Math.round(Math.sin(rotate*3)*3)
  p4.y = 8+Math.round(Math.cos(rotate*3)*3)
  p5.x = 8+Math.round(Math.sin(rotate*2)*4)
  p5.y = 8+Math.round(Math.cos(rotate*2)*4)
  p6.x = 8+Math.round(Math.sin(rotate*1)*5)
  p6.y = 8+Math.round(Math.cos(rotate*1)*5)
  p7.x = 8+Math.round(Math.sin(rotate/2)*5)
  p7.y = 8+Math.round(Math.cos(rotate/2)*5)
  p8.x = 8+Math.round(Math.sin(rotate/3)*5)
  p8.y = 8+Math.round(Math.cos(rotate/3)*5)
  p9.x = 8+Math.round(Math.sin(rotate/4)*5)
  p9.y = 8+Math.round(Math.cos(rotate/4)*5)
};

function update(){
  movePlanets(rot);
  rot++;
  setTimeout(update,500);
};
update();